package com.smartbone.util;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtils {

	public static String getUsername() {
		String username = "";
		if (SecurityContextHolder.getContext() != null
				&& SecurityContextHolder.getContext().getAuthentication() != null) {

			Object principal = SecurityContextHolder.getContext()
					.getAuthentication().getPrincipal();

			if (principal instanceof UserDetails) {
				UserDetails userDetails = (UserDetails) principal;

				username = userDetails.getUsername();
			}
		}
		
		return username;
	}
	
	public static boolean isLogin() {
		  boolean login = false;
	      if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {
				
				Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
				
				if (principal instanceof UserDetails) {
					login = true;
				}
			}
	      
	      return login;
	      
	}
	
}
